<?php defined('IN_PHPCMS') or exit('Access Denied'); ?><?php include template('member','header'); ?>
<script type="text/javascript" src="images/js/validator.js"></script>
<div id="main">
  <?php include template('order' , 'left'); ?>
  <div id="right">
    <p id="position"> <strong>当前位置：</strong><a href="">首页</a><a href="<?php echo $MODULE['member']['url'];?>">会员中心</a><a href="<?php echo $M['url'];?>">订单</a>在线下单</p>
    <form action="<?php echo $M['url'];?>order.php?action=confirm" method="post" name="myform" id ="myform">
    <input type="hidden" name="goodsid" value="<?php echo $goodsid;?>" />
    <input type="hidden" name="goodsname" value="<?php echo $goodsname;?>" />
    <input type="hidden" name="goodsurl" value="<?php echo $goodsurl;?>" />
    <input type="hidden" name="unit" value="<?php echo $unit;?>" />
    <input type="hidden" name="price" value="<?php echo $price;?>" />
    <input type="hidden" name="carriage" value="<?php echo $carriage;?>" />
    <input type="hidden" name="stock" value="<?php echo $stock;?>" />
    <input type="hidden" name="verify" value="<?php echo $verify;?>" />
    <input type="hidden" name="forward" value="<?php echo $forward;?>" />
    <input type="hidden" name="isnewdeliver" value="<?php if($delivers) { ?>0<?php } else { ?>1<?php } ?>" />
    <table cellpadding="0" cellspacing="1" class="table_form">
      <caption>订单信息</caption>
  <tr>
        <th width="15%">产品ID：</th>
        <td><?php echo $goodsid;?></td>       
      </tr>
  <tr>
        <th>产品名称：</th>
        <td><a href="<?php echo $goodsurl;?>" target="_blank"><?php echo $goodsname;?></a></td>       
      </tr>
<?php if($carriage) { ?>
  <tr>
        <th>产品运费：</th>
        <td>￥<?php echo $carriage;?>元</td>       
      </tr>
<?php } ?>
      <tr>
        <th>产品单价：</th>
        <td>￥<?php echo $price;?>元/<?php echo $unit;?></td>       
      </tr>
<?php if($stock) { ?>
  <tr>
        <th>库存：</th>
        <td><?php echo $stock;?> <?php echo $unit;?></td>       
      </tr>
  <tr>
        <th><font color="red">*</font> 订购数量：</th>
        <td><input type="text" name="number" value="<?php echo $number;?>" size="6" require="true" datatype="range|number" max="<?php echo $stock;?>" msg="当前库存数量为<?php echo $stock;?>，请重新填写|请填写正确的数量" msgid="msg_number"/> <?php echo $unit;?><span id="msg_number"></span></td>       
      </tr>
<?php } else { ?>
      <tr>
        <th><font color="red">*</font> 订购数量：</th>
        <td><input type="text" name="number" value="<?php echo $number;?>" size="6" require="true" datatype="number" msg="请填写正确的数量" msgid="msg_number"/> <?php echo $unit;?><span id="msg_number"></span></td>       
      </tr>
<?php } ?>
      <tr>
        <th>给卖家留言：</th>
        <td><textarea name="note" id="note" rows="4" cols="60"></textarea></td>       
      </tr>
    </table>
<?php if($delivers) { ?>
    <table cellpadding="0" cellspacing="1" class="table_list">
      <caption>确认您的收货地址</caption>
  <tr>
        <th width="60">收货人</th>
        <th width="60">配送区域</th>
        <th width="90">电话</th>
        <th width="90">手机</th>
        <th>地址</th>
        <th width="50">邮编</th>
        <th width="80">操作</th>
  </tr>
<?php if(is_array($delivers)) foreach($delivers AS $k => $d) { ?>
 	  <tr>
        <td><input type="radio" name="deliverid" value="<?php echo $d['deliverid'];?>" <?php if($k==0) { ?>checked<?php } ?> onclick="set_deliverid(this.value);"/></td>
        <td id="consignee_<?php echo $d['deliverid'];?>"><?php echo $d['consignee'];?></td>
        <td><?php echo $AREA[$d['areaid']]['name'];?><input type="hidden" name="areaid_<?php echo $d['deliverid'];?>" id="areaid_<?php echo $d['deliverid'];?>" value="<?php echo $d['areaid'];?>"><input type="hidden" name="areaname_<?php echo $d['deliverid'];?>" id="areaname_<?php echo $d['deliverid'];?>" value="<?php echo $AREA[$d['areaid']]['name'];?>"></td>
        <td id="telephone_<?php echo $d['deliverid'];?>"><?php echo $d['telephone'];?></td>
        <td id="mobile_<?php echo $d['deliverid'];?>"><?php echo $d['mobile'];?></td>
        <td id="address_<?php echo $d['deliverid'];?>"><?php echo $d['address'];?></td>
        <td id="postcode_<?php echo $d['deliverid'];?>"><?php echo $d['postcode'];?></td>
  </tr>
<?php } ?>
   </table>
<?php } ?>
<table cellpadding="0" cellspacing="1" id="newdeliver" style="display:<?php if($delivers) { ?>none<?php } ?>" class="table_form">
    <caption><?php if($delivers) { ?>新增<?php } ?>收货地址</caption>
  <tr>
        <th width="15%"><font color="red">*</font> 配送区域：</th>
        <td>
            <input type="hidden" name="d[areaid]" id="areaid" value="<?php echo $areaid;?>">
  <?php if($areaid) { ?>
<span id="areaname" style="cursor:pointer;" onClick="this.style.display='none';$('#reselect_areaid').show();"><?php echo $AREA[$areaid]['name'];?> <font color="red">点击重选</font></span>
<span id="reselect_areaid" style="display:none;">
<span id="load_areaid"></span> 
<a href="javascript:areaid_reload();">重选</a>
</span>
  <?php } else { ?>
<span id="load_areaid"></span>
<a href="javascript:areaid_reload();">重选</a>
  <?php } ?>
        </td> 
      </tr>
      <tr>
        <th><font color="red">*</font> 收货人：</th>
        <td><input type="text" name="d[consignee]" id="consignee" value="<?php echo $consignee;?>" size="12" require="true" datatype="require" msg="请填写收货人"/></td>       
      </tr>
  <tr>
        <th><font color="red">*</font> 电话：</th>
        <td><input type="text" name="d[telephone]" id="telephone" value="<?php echo $telephone;?>" size="20" require="true" datatype="custom" regexp="^[\d|\-|\+]{3,20}$"  msg="请填写正确的电话" msgid="telephone_notice"/> 格式：010-10000000-801 <span id="telephone_notice"></span></td>     
      </tr>
  <tr>
        <th><font color="red">*</font> 手机：</th>
        <td><input type="text" name="d[mobile]" id="mobile" value="<?php echo $mobile;?>" size="20" require="true" datatype="mobile" msg="请填写正确的手机" msgid="mobile_notice"/> 格式：13800000000 <span id="mobile_notice"></span></td>       
      </tr>
  <tr>
        <th><font color="red">*</font> 地址：</th>
        <td><input type="text" name="d[address]" id="address" value="<?php echo $address;?>" size="60" require="true" datatype="require" msg="填写正确的地址"/></td>       
      </tr>
      <tr>
        <th><font color="red">*</font> 邮编：</th>
        <td><input type="text" name="d[postcode]" id="postcode" value="<?php echo $postcode;?>" size="8" require="true" datatype="zip" msg="填写正确的邮编" msgid="postcode_notice"/> 格式：100000 <span id="postcode_notice"></span></td>       
      </tr>
</table>
<?php if($delivers) { ?>
<div class="button_box" style="padding-left:10px"><input type="button" name="dosubmit" value="新增收货地址" style="width:100px" onclick="add_deliver();" />&nbsp;&nbsp;<input type="submit" name="dosubmit" value=" 下一步 " /></div>
<?php } else { ?>
<div class="button_box" style="padding-left:120px"><input type="submit" name="dosubmit" value=" 下一步 " /></div>
<?php } ?>
   </form>	
  </div>
</div>
<div class="clear"></div>
<?php include template('phpcms','footer'); ?>
<script language="javascript" type="text/javascript">
$().ready(function() {
  <?php if($delivers) { ?>
  change_deliver('false');
  set_deliverid(deliverid);
  <?php } ?>
  $('form').checkForm(1);
});

var deliverid = '<?php echo $delivers['0']['deliverid'];?>';
function set_deliverid(deliverid)
{
$('#areaid').val($('#areaid_'+deliverid).val());
$('#areaname').val($('#areaname_'+deliverid).val());
$('#consignee').val($('#consignee_'+deliverid).html());
$('#telephone').val($('#telephone_'+deliverid).html());
$('#mobile').val($('#mobile_'+deliverid).html());
$('#address').val($('#address_'+deliverid).html());
$('#postcode').val($('#postcode_'+deliverid).html());
}

function add_deliver()
{
    $('#newdeliver').show();
    $('#isnewdeliver').val('1');
change_deliver('true');
}

function change_deliver(val)
{
    $('#consignee').attr('require', val);
    $('#telephone').attr('require', val);
    $('#mobile').attr('require', val);
    $('#address').attr('require', val);
    $('#postcode').attr('require', val);
$('form').checkForm(1);
}

function areaid_load(id)
{
$.get("load.php", { field: 'areaid', id: id }, function(data){
$('#load_areaid').append(data);
});
}

function areaid_reload()
{
$('#load_areaid').html('');
areaid_load(0);
}
areaid_reload();
</script>